﻿using Dapper;
using Infrastructure.DataBaseConnect;
using Infrastructure.IRepository.Sys;
using Model.BusinessModel.OutPut.sys;
using Model.DomainModel.Sys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.Repository.Sys
{
    /// <summary>
    /// 登录日志仓储接口实现
    /// </summary>
    public class SysLoginLogRepository : Repository<SysLoginLog>, ISysLoginLogRepository
    {

        /// <summary>
        /// 获取登录日志
        /// </summary>
        /// <returns>返回指定数据</returns>
        public List<LoginLogOutPut> GetLoginLogMsg()
        {
            string sql = @" SELECT sc.CorporationName,sl.Ip,sl.Isp,sl.Country,sl.Prov,sl.City,sl.Area,sl.CreateTime,sl.Lat,sl.Lng,su.UserName FROM [Sys_LoginLog] as sl
                            inner join Sys_Corporation as sc on sl.CorporationKey = sc.CorporationKey
                            inner join Sys_User as su on su.UserId = sl.UserId
                            order by sl.CreateTime desc  ";
            using var connection = DataBaseConnectConfig.GetSqlConnection();
            return connection.Query<LoginLogOutPut>(sql).ToList();

        }
    }
}
